import urllib
from HTMLParser import HTMLParser

class MyHTMLParser(HTMLParser):
  def __init__(self):
    HTMLParser.__init__(self)
    self.mode = ""
    self.data = []
    
  def handle_starttag(self, tag, attrs):
    if tag == "tr":
      #if [v for k, v in attrs if k=='align' and v=='left']:
      self.mode = "date"
      #else:
        #self.mode = "data"

  def handle_data(self, text):
    if len(text)>2:
      if self.mode == "date":
        text += ",13:45"
        self.mode = "data"
      self.data.append(text)
      
  def handle_endtag(self, tag):
    if tag == "tr":
      print ",".join(self.data)
      self.data = []
      self.mode = ""

def main():
  sock = urllib.urlopen("http://www.dbmaker.com.tw/stock/cgihistory.cgi?id=WTX1&begin=2004&end=2100")
  MyHTMLParser().feed(sock.read())
  sock.close()
  
if __name__ == "__main__":
  main()